package face.pay.cpn.controller;

import face.pay.cpn.service.IGetCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
public class CpnConvertController {


    @Autowired
    IGetCouponService iGetCouponService;
    /**
     *兑换优惠券
     * @return
     */
    @RequestMapping(value = "/getCpn")
    public String getCpn(String cpn_auth_code, Model model, HttpServletRequest request) {
        log.info("优惠券领取："+cpn_auth_code);
        try {
            String url = iGetCouponService.getCpn(cpn_auth_code,model,request);
            return"redirect:"+url;
        }catch (Exception e){
            log.error("领取优惠券失败",e);
            return "error";
        }
    }

    @RequestMapping(value = "/cpnAuth")
    public String cpnAuth(String code, String state,Model model, HttpServletRequest request) {

        iGetCouponService.cpnAuth(code,state,model,request);

        return  "convert";


    }
}
